package com.zrar.ak.gkpt.controller.record;

import com.zrar.ak.gkpt.model.vo.UserVO;
import com.zrar.ak.gkpt.service.record.IBusinessOntractInfoService;
import com.zrar.ak.gkpt.service.user.IUserService;
import com.zrar.ak.gkpt.util.FormDataParameter;
import com.zrar.ak.gkpt.util.JsonPageResult;
import com.zrar.ak.gkpt.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: BusinessOntractController
 * @Description: 合同管理controller层
 * @Author: CaoTao
 * @Create: 2020/04/07
 */
@RestController
@RequestMapping("/ontract")
@Api(tags = "合同管理相关接口")
public class BusinessOntractInfoController {
    @Autowired
    private IBusinessOntractInfoService BusinessOntractInfoService;
    @Autowired
    private IUserService userService;

    @RequestMapping(value = "save", method = RequestMethod.POST, produces = {"application/json;charset = utf-8"})
    @ApiOperation(value = "保存合同基本信息", httpMethod = "POST", notes = "保存合同基本信息")
    public JsonResult ontractInfoSave(HttpServletRequest request,
                                      @ApiParam(name = "formDataParameter", value = "合同基本信息参数") @RequestBody FormDataParameter formDataParameter) {
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVo = userService.getUserInformation(request);
        jsonResult = BusinessOntractInfoService.OntractInfoSave(jsonResult, formDataJson, userVo);
        return jsonResult;
    }

    @RequestMapping(value = "delete", method = RequestMethod.DELETE, produces = {"application/json;charset = utf-8"})
    @ApiOperation(value = "删除合同基本信息", httpMethod = "DELETE", notes = "根据合同编号修改状态码")
    public JsonResult ontractInfoDelete(@ApiParam(name = "id", value = "主键id") @RequestParam(name = "id") String id) {
        JsonResult jsonResult = new JsonResult();
        jsonResult = BusinessOntractInfoService.deleteOntractInfoByontractId(jsonResult, id);
        return jsonResult;
    }

    @RequestMapping(value = "update", method = RequestMethod.PUT, produces = {"application/json;charset = utf-8"})
    @ApiOperation(value = "更新合同基本信息", httpMethod = "PUT", notes = "更新合同基本信息")
    public JsonResult ontractInfoUpdate(HttpServletRequest request, @ApiParam(name = "formDataParameter",
            value = "合同基本信息参数") @RequestBody FormDataParameter formDataParameter) {
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVo = userService.getUserInformation(request);
        jsonResult = BusinessOntractInfoService.OntractInfoUpdate(jsonResult, formDataJson, userVo);
        return jsonResult;
    }

    @RequestMapping(value = "query", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据主键id获取信息", httpMethod = "GET", notes = "根据主键id获取信息")
    public JsonResult ontractInfoGetById(@ApiParam(name = "id", value = "主键id")
                                         @RequestParam(value = "id") String id) {
        JsonResult jsonResult = new JsonResult();
        jsonResult = BusinessOntractInfoService.queryOntractInfoById(jsonResult, id);
        return jsonResult;
    }

    @RequestMapping(value = "getAccountInfoList", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "获取测试验证信息列表-分页查询和条件查询", httpMethod = "GET", notes = "获取测试验证信息列表-分页查询和条件查询")
    public JsonPageResult getAccountInfoList(HttpServletRequest request,
                                             @ApiParam(name = "currentPage", value = "当前页") @RequestParam int currentPage,
                                             @ApiParam(name = "pageSize", value = "每页条数限制") @RequestParam int pageSize,
                                             @ApiParam(name = "unitName", value = "建设单位名称(模糊查询)") @RequestParam(value = "unitName", required = false) String unitName,
                                             @ApiParam(name = "contractCode", value = "合同编号(模糊查询)") @RequestParam(value = "contractCode", required = false) String contractCode) {
        JsonPageResult jsonResult = new JsonPageResult();
        jsonResult = BusinessOntractInfoService.getOntractInfoList(jsonResult, currentPage, pageSize, unitName,contractCode);
        return jsonResult;
    }
}
